<?php session_start();
validaAcesso();
require_once"funcoes/bibl_midias.jsp";
require_once"funcoes/com_hostels.jsp";

echo"<h2> ".$_SESSION["menu"]["rel"][30]."</h2>
  <form method='POST' action='index.jsp?rel=30&cont=1' autocomplete='off'>";
?>

  
  <br>
  <div class='item'><h5>Selecione o M&ecirc;s:</h5><select name='pmes'>
   <option value="0">Todos os Meses</option>
   <option value="01">Janeiro</option>
   <option value="02">Fevereiro</option>
   <option value="03">Mar&ccedil;o</option>
   <option value="04">Abril</option>
   <option value="05">Maio</option>
   <option value="06">Junho</option>
   <option value="07">Julho</option>
   <option value="08">Agosto</option>
   <option value="09">Setembro</option>
   <option value="10">Outubro</option>
   <option value="11">Novembro</option>
   <option value="12">Dezembro</option>
  </select></div>

  <div class='item'><h5>Selecione o Ano:</h5><select name='pano'>
  <?php
  $sql = "select distinct(EXTRACT(YEAR FROM data_inicio )) from bibl_emprestimos where ref_inst = {$_SESSION[ID_HOSTEL_]} order by data_inicio desc";
  $ln=$_SESSION['ADOCnn']->Execute("$sql");
  if($ln->RecordCount() != 0 ){
  	while(!$ln->EOF){
  		echo"<option value='{$ln->fields[0]}'>{$ln->fields[0]}</option>";
  		$ln->MoveNext();
  	}
  }
  ?>
  </select></div>
  
     <div class='item'><h5>Institui&ccedil;&atilde;o:</h5>
      <select name='pid_hostel'>
  <?php

  getHostels($_SESSION["ID_HOSTEL_"],"select");


  echo"</select></div> <br><br>
          
      		
	    	<!--<div class='item'><h5>Exibir Gr&aacute;fico:</h5><input type='checkbox' name='grafico' value='1' checked></div>-->
        	<div class='item'><h5></h5><input type='submit' value='Gerar Relat&oacute;rio'></div>
        	      <div align='right'><a href=\"javascript:void(0);\" onclick=\"getLink('rel',7,false);\"><img src='images/seta_voltar.gif' border='0'> voltar para Listagem de Relat&oacute;rios</a></div>
          </form>";

  if($_GET["cont"]==1){
  	
	if ($_POST["pmes"] == 0) {
		$cond = "YEAR";
		$value = $_POST["pano"];
		
	}else{
		$cond = "YEAR_MONTH";
		$value = "{$_POST["pano"]}{$_POST["pmes"]}";
	}
  	
  	
  	echo "<h2>";
  	getHostels($_POST["pid_hostel"],"texto");
  	echo "<br>M&ecirc;s / Ano: {$_POST["pmes"]} / {$_POST["pano"]}</h2><br /><br />";





  	$class="odd";
  	$dadosGrafico = "";

  	#################### EMPRESTIMOS ################################################
  	
  	$sql="SELECT count(*) FROM bibl_emprestimos WHERE
             (EXTRACT($cond FROM data_inicio ) = $value)";
  	$ln=$_SESSION['ADOCnn']->Execute("$sql");
  	$total_emprest_geral = $ln->fields[0];
    //echo $sql;

  	$sql1="SELECT count(*) FROM bibl_emprestimos WHERE
             (EXTRACT($cond FROM data_inicio ) = $value) and ref_inst = {$_POST["pid_hostel"]}";
  	$ln1=$_SESSION['ADOCnn']->Execute("$sql1");
  	$total_emprest_inst = $ln1->fields[0];
  	//echo $sql1;

  	
	#################### DEVOLUCOES ################################################
  	
  	$sql="SELECT count(*) FROM bibl_emprestimos WHERE
             (EXTRACT($cond FROM data_devolucao ) = $value)";
  	$ln=$_SESSION['ADOCnn']->Execute("$sql");
  	$total_devolv_geral = $ln->fields[0];
  	//echo $sql;

  	$sql1="SELECT count(*) FROM bibl_emprestimos WHERE
             (EXTRACT($cond FROM data_devolucao ) = $value) and ref_inst = {$_POST["pid_hostel"]}";
  	$ln1=$_SESSION['ADOCnn']->Execute("$sql1");
  	$total_devolv_inst = $ln1->fields[0];
  	//echo $sql1;  	
  	
  	
  	#################### RESERVAS ################################################
  	
  	$sql="SELECT count(*) FROM bibl_reservadas WHERE
             (EXTRACT($cond FROM data_cad_reserva ) = $value)";
  	$ln=$_SESSION['ADOCnn']->Execute("$sql");
  	$total_reserv_geral = $ln->fields[0];
  	//echo $sql;

  	$sql1="SELECT count(*) FROM bibl_reservadas WHERE
             (EXTRACT($cond FROM data_cad_reserva ) = $value) and ref_inst = {$_POST["pid_hostel"]}";
  	$ln1=$_SESSION['ADOCnn']->Execute("$sql1");
  	$total_reserv_inst = $ln1->fields[0];
  	//echo $sql1;
  	
  	
  	#################### TOMBOS ################################################
  	
  	$sql="SELECT count(*) FROM bibl_midias WHERE
             (EXTRACT($cond FROM data_cadastro ) = $value)";
  	$ln=$_SESSION['ADOCnn']->Execute("$sql");
  	$total_tombo_geral = $ln->fields[0];
  	//echo $sql;

  	$sql1="SELECT count(*) FROM bibl_midias WHERE
             (EXTRACT($cond FROM data_cadastro ) = $value) and ref_inst = {$_POST["pid_hostel"]}";
  	$ln1=$_SESSION['ADOCnn']->Execute("$sql1");
  	$total_tombo_inst = $ln1->fields[0];
  	//echo $sql1;
  	
  	
  	#################### MEMBROS ################################################
  	
  	$sql="SELECT count(*) FROM pes_pessoas WHERE
             (EXTRACT($cond FROM data_cadastro ) = $value)";
  	$ln=$_SESSION['ADOCnn']->Execute("$sql");
  	$total_membro_geral = $ln->fields[0];
  	//echo $sql;

  	$sql1="SELECT count(*) FROM pes_pessoas WHERE
             (EXTRACT($cond FROM data_cadastro ) = $value) and ref_inst = {$_POST["pid_hostel"]}";
  	$ln1=$_SESSION['ADOCnn']->Execute("$sql1");
  	$total_membro_inst = $ln1->fields[0];
  	//echo $sql1;
  	
  	function getMedia ($parte, $total){
  		
  		$porcentagem = (($parte * 100) / $total);
  		
  		return round($porcentagem,2);
  	}
  	
  	echo"
                 <table class='perfil $class'>
                    <tr class='titulo'>
                       <td colspan=2>Total de Empr&eacute;stimos</td>
                    </tr>
                    <tr>
                       <td width=500>de todo acervo</td>
                       <td class='dindin'>$total_emprest_geral = 100% </td>
                    </tr>
                    <tr>
                       <td width=500>da biblioteca:"; getHostels($_POST["pid_hostel"],"texto");
  			    echo" </td>
                       <td class='dindin'>$total_emprest_inst = ".getMedia($total_emprest_inst, $total_emprest_geral)."%  </td>
                    </tr>
					<tr>
                       <td colspan=2>&nbsp;</td>
                    </tr>                    
					
                    
                    <tr class='titulo'>
                       <td colspan=2>Total de Devolu&ccedil;&otilde;es</td>
                    </tr>
                    <tr>
                       <td width=500>de todo acervo</td>
                       <td class='dindin'>$total_devolv_geral = 100%</td>
                    </tr>
                    <tr>
                       <td width=500>da biblioteca:"; getHostels($_POST["pid_hostel"],"texto");
  			    echo" </td>
                       <td class='dindin'>$total_devolv_inst  = ".getMedia($total_devolv_inst, $total_devolv_geral)."%</td>
                    </tr>                    
                    <tr>
                       <td colspan=2>&nbsp;</td>
                    </tr>   
                    
                    
					<tr class='titulo'>
                       <td colspan=2>Total de Reservas</td>
                    </tr>
                    <tr>
                       <td width=500>de todo acervo</td>
                       <td class='dindin'>$total_reserv_geral = 100%</td>
                    </tr>
                    <tr>
                       <td width=500>da biblioteca:"; getHostels($_POST["pid_hostelpid_hostel"],"texto");
  			    echo" </td>
                       <td class='dindin'>$total_reserv_inst = ".getMedia($total_reserv_inst, $total_reserv_geral)."%</td>
                    </tr>                    
                    <tr>
                       <td colspan=2>&nbsp;</td>
                    </tr>   
                    
                    
                    <tr class='titulo'>
                       <td colspan=2>Total de Cadastros de Tombos</td>
                    </tr>
                    <tr>
                       <td width=500>de todo acervo</td>
                       <td class='dindin'>$total_tombo_geral = 100%</td>
                    </tr>
                    <tr>
                       <td width=500>da biblioteca:"; getHostels($_POST["pid_hostel"],"texto");
  			    echo" </td>
                       <td class='dindin'>$total_tombo_inst = ".getMedia($total_tombo_inst, $total_tombo_geral)."%</td>
                    </tr>
                    <tr>
                       <td colspan=2>&nbsp;</td>
                    </tr>   
                    
                    
                    
                    <tr class='titulo'>
                       <td colspan=2>Total de Cadastros de Membros / S&oacute;cios</td>
                    </tr>
                    <tr>
                       <td width=500>de todo acervo</td>
                       <td class='dindin'>$total_membro_geral = 100%</td>
                    </tr>
                    <tr>
                       <td width=500>da biblioteca:"; getHostels($_POST["pid_hostel"],"texto");
  			    echo" </td>
                       <td class='dindin'>$total_membro_inst  = ".getMedia($total_membro_inst, $total_membro_geral)."%</td>
                    </tr>
                    <tr>
                       <td colspan=2>&nbsp;</td>
                    </tr>   
                    
                    
                 </table>

      ";



  	/*
  	if($ln1->RecordCount() != 0 ){
  	while(!$ln1->EOF){

  	$cod = $ln1->fields[0];
  	$qtd = $ln1->fields[1];
  	$nome = getMidia($cod,"titulo");

  	if (!empty($nome)) {


  	if ($qtd >2) {
  	if($class == "odd"){$class="even";}else{$class="odd";}
  	echo"
  	<table class='perfil $class'>
  	<tr>
  	<td width=500>$nome</td>
  	<td class='dindin'>$qtd</td>
  	</tr>
  	</table>
  	";

  	$dadosGrafico .= "<set name='$nome' value='$qtd' color='".getFCColor()."'/>";
  	}

  	}

  	$ln1->MoveNext();
  	}
  	}

  	*/



  	###inicio grafico #####################
  	if ($_POST["grafico"] == 1) {

  		$w = 740;
  		$h = 350;

  		$head = "<graph caption='' xAxisName='' yAxisName='Unidades' rotateNames='1' decimalPrecision='0' formatNumberScale='0' chartRightMargin='20'>";


  		echo "
		<div align='left'>
		  <OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='$w' height='$h' id='Column3D' >
		    <param name='movie' value='admin/fusion_charts/Charts/FCF_Column3D.swf' />
		    <param name='FlashVars' value=\"&chartWidth=$w&chartHeight=$h&dataXML=$head $dadosGrafico</graph>\">
		    <param name='quality' value='high' />
		    <embed src='admin/fusion_charts/Charts/FCF_Column3D.swf' flashVars=\"&chartWidth=$w&chartHeight=$h&dataXML=$head $dadosGrafico</graph>\" quality='high' width='$w' height='$h' name='Grafico' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />
		  </object>
		</div>
		
		";
  	}
  	###fim grafico #####################


  }
?>
